package com.freecloud.bitorrent.domain.server.command;

import com.freecloud.bitorrent.constant.LocalNodeConstant;
import com.freecloud.bitorrent.convert.BitTorrentConvert;
import com.freecloud.bitorrent.demo.bo.PingArguments;
import com.freecloud.bitorrent.demo.bo.RequestMessage;
import com.freecloud.bitorrent.demo.bo.ResponseMessage;
import com.freecloud.bitorrent.domain.server.support.DhtCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Author: maomao
 * @Date: 2022/7/18 6:43 PM
 */
@Slf4j
@Component("ping")
public class PingCommand implements DhtCommand {

    /**
     * 返回本机固定id
     */
    private static final PingArguments RESPONSE_PING_ARGUMENTS = new PingArguments(LocalNodeConstant.ip);

    @Override
    public ResponseMessage response(RequestMessage requestMessage) {
        log.info("ping PingCommand requestMessage : {}", requestMessage);
        ResponseMessage responseMessage = BitTorrentConvert.INSTANCE.request2Response(requestMessage);
        responseMessage.setResult(RESPONSE_PING_ARGUMENTS);
        return responseMessage;
    }
}
